﻿using System.IO;
using System.Media;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using WMPLib;

namespace TeamRobin.BattleCity.Core.Utils
{
	internal static class Sounds
	{
		public static bool IsEngineRunning;
		public static WindowsMediaPlayer Player = new WindowsMediaPlayer();
		public static string AppDirectory = Directory.GetParent(Assembly.GetExecutingAssembly().Location).Parent.Parent.FullName;
		public static void TankEngine()
		{
			IsEngineRunning = true;
			Task.Run(() =>
			{
				var path = AppDirectory + @"\Content\Sounds\TankMoving.wav";
				while (IsEngineRunning)
				{
					Player.URL = path;
					Player.controls.play();
					Thread.Sleep(5000);
				}
				Player.controls.stop();
			});
		}
		public static void FireWeapon()
		{
			using (SoundPlayer fireWeapon = new SoundPlayer(@"..\..\Content\Sounds\FireWeapon.wav"))
			{
				fireWeapon.Play();
				Thread.Sleep(500);
			}
		}
		public static void NewGameLevelSound()
		{
			using (SoundPlayer newGameLevel = new SoundPlayer(@"..\..\Content\Sounds\StartNew.wav"))
			{
				newGameLevel.Play();
			}
		}
		public static void PowerUp()
		{
			using (SoundPlayer powerUp = new SoundPlayer(@"..\..\Content\Sounds\PowerUp.wav"))
			{
				powerUp.Play();
			}
		}
		public static void Highscore()
		{
			using (SoundPlayer highscoreReached = new SoundPlayer(@"..\..\Content\Sounds\Highscore.wav"))
			{
				highscoreReached.Play();
			}
		}
		public static void EnenmyKilled()
		{
			using (SoundPlayer enemyKilled = new SoundPlayer(@"..\..\Content\Sounds\EnenmyKilled.wav"))
			{
				enemyKilled.Play();
			}
		}
		public static void GameOver()
		{
			using (SoundPlayer gameOver = new SoundPlayer(@"..\..\Content\Sounds\Gameover.wav"))
			{
				gameOver.Play();
			}
		}
	}
}